using NUnit.Framework;

namespace Agile.Common.Tests
{
	using System.Data;
	using Agile.Common.Testing;

	/// <summary>
	/// Summary description for CollectionTests.
	/// </summary>
	[TestFixture]
	public class CollectionTests
	{
		#region GetForDisplayWithHeader Tests

		/// <summary>
		/// Verifies the GetForDisplay method returns a table with the values from the specified columns
		///		- Create a test collection of Widgets
		///		- Check the values of the second row
		///		- Check the values of the third row
		///		- Check the values of the fourth row
		/// </summary>
		[Test]
		public void GetForDisplayWithHeaderTests()
		{
			// Create a test collection of Widgets
			WidgetCollection widgets = WidgetCollection.GetTestCollectionWithThreeItems();
			widgets.Sort();
			DataTable table = widgets.GetForDisplay("Name", "Author");
			// Check the first row is the column headers
			Assert.AreEqual(table.Rows[0]["Name"], "a third", "Check the column headers");
			Assert.AreEqual(table.Rows[0]["Author"], "Astro Boy", "Check the column headers");
			// Check the values of the second row
			Assert.AreEqual(table.Rows[1]["Name"], "first", "Check the column headers");
			Assert.AreEqual(table.Rows[1]["Author"], "Forest Gump", "Check the column headers");

			// Check the values of the third row
			Assert.AreEqual(table.Rows[2]["Name"], "second", "Check the column headers");
			Assert.AreEqual(table.Rows[2]["Author"], "Billy Joe Armstrong", "Check the column headers");

		}

		#endregion

		#region GetForDisplayUsingSpacesInPropertyName Tests
		/// <summary>
		/// Verifies the GetForDisplay method returns a table with the values from the specified columns
		///		- Create a test collection of Widgets
		///		- Check the values of the second row
		///		- Check the values of the third row
		///		- Check the values of the fourth row
		/// </summary>
		[Test]
		public void GetForDisplayUsingSpacesInPropertyNameTests()
		{
			// Create a test collection of Widgets
			WidgetCollection widgets = WidgetCollection.GetTestCollectionWithThreeItems();
			widgets.Sort();
			DataTable table = widgets.GetForDisplay("Na me", "Auth or");
			// Check the first row is the column headers
			Assert.AreEqual(table.Rows[0]["Na me"], "a third", "Check the column headers");
			Assert.AreEqual(table.Rows[0]["Auth or"], "Astro Boy", "Check the column headers");
			// Check the values of the second row
			Assert.AreEqual(table.Rows[1]["Na me"], "first", "Check the column headers");
			Assert.AreEqual(table.Rows[1]["Auth or"], "Forest Gump", "Check the column headers");

			// Check the values of the third row
			Assert.AreEqual(table.Rows[2]["Na me"], "second", "Check the column headers");
			Assert.AreEqual(table.Rows[2]["Auth or"], "Billy Joe Armstrong", "Check the column headers");
		}

		#endregion
	}
}
